package com.b2j.routines;

import com.b2j.base.ErrorManager;
import com.b2j.base.Lexema;
import com.b2j.base.MainTools;
import com.b2j.base.Routine;
import com.b2j.base.Token;

public class Signal extends Routine {

	@Override
	public String generate(Lexema lexema) {
		String line = "";
		String identifier = "";
		String message = "";
		lexema = MainTools.tools.nextLexema();
		if (lexema.tokenType == Token.OPARENT) {

			identifier = MainTools.tools.processCodeUntil(lexema, Token.COMMA);
			message = MainTools.tools.processCodeUntil(lexema, Token.CPARENT);
			
		} else {
			ErrorManager.unexpected(lexema);
		}
		
		if (identifier.toLowerCase().equals("id"))
			identifier = "this";
		
		line = "(" + identifier + ")." + "setSignal(" + message + ")";
		
		return line;
	}


}
